package com.ji;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Title:
 * Description:
 * Author:吉
 * Since:2017/5/19
 * Version:1.1.0
 */
public class SessionManager {
    private static Map<Integer, NioSession> sessionPool = new ConcurrentHashMap<Integer, NioSession>();

    private static final AtomicInteger connectionsCounter = new AtomicInteger(0);

    public static void create(NioSession session) {
        sessionPool.put(connectionsCounter.getAndIncrement(), session);
    }

    public static NioSession get(int sessionId) {
        return sessionPool.get(sessionId);
    }

    public static void close(int sessionId) {
        sessionPool.get(sessionId).close();
    }

    public  static Collection<NioSession> getAllSession(){
        return sessionPool.values();
    }
}
